package com.yuan.blog.controller;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuan.blog.service.impl.NormalUserService;
import com.yuan.blog.utils.ApacheHttpUtils;
import com.yuan.blog.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @program: blog-core
 * @description:
 * @author: yuan_boss
 * @create: 2023-01-07 08:50
 **/
@RestController
@RequestMapping("/user")
public class NormalUserController {

    @Value("${blog.web.url}")
    private String baseUrl;

    @Autowired
    private NormalUserService userService;

    @PostMapping("/page")
    @ResponseBody
    public R page(@RequestBody Page page){
        String s = JSON.toJSONString(page);
        String json = ApacheHttpUtils.postJson(baseUrl + "UserController/page",s);
        //去除多余的信息
        List<Map> maps = userService.clear(json);
        return R.ok().put("data", maps);
    }

    public static void main(String[] args) {
//        Page page = new Page();
//        page.setSize(2);
//        page.setCurrent(1);
//        String s = JSON.toJSONString(page);
//        String json = ApacheHttpUtils.postJson(baseUrl + "UserController/page",s);
//        //去除多余的信息
//        List<Map> maps = userService.clear(json);


    }
}
